package com.mark.springsecurity.dto.req;

import com.mark.springsecurity.domain.SysUser;
import lombok.Data;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;

@Data
public class SysUserQueryObj {

    private String realName;

    private String username;

    private String role;
    
    public static Example<SysUser> buildExample(SysUserQueryObj sysUserQueryObj) {
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withIgnoreCase("realName")
                .withIgnoreNullValues()
                .withMatcher("realName", ExampleMatcher.GenericPropertyMatchers.contains());

        return Example.of(SysUser.builder()
                .realName(sysUserQueryObj.getRealName())
                .username(sysUserQueryObj.getUsername())
                .role(sysUserQueryObj.getRole())
                .enabled(Boolean.TRUE)
                .build(), matcher);
    }
}
